import { _decorator, Component, Node, tween, UIOpacity } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('LightItem')
export class LightItem extends Component {
    @property(Node) lightNode1: Node = null!;
    @property(Node) lightNode2: Node = null!;

    @property(Node) startNode: Node = null!;
    @property(Node) startNode2: Node = null!;

    start() {
        this.onShine(this.startNode);
        this.onShine(this.startNode2);
    }

    update(deltaTime: number) {
        // lightNode1 顺时针旋转，lightNode2 逆时针旋转
        if (this.lightNode1) {
            this.lightNode1.angle += 60 * deltaTime;
        }
        if (this.lightNode2) {
            this.lightNode2.angle -= 60 * deltaTime;
        }
    }

    private onShine(target: Node) {
        const op = target.getComponent(UIOpacity);
        tween(op)
            .to(0.5, { opacity: 255 })
             .to(0.5, { opacity: 0 })
             .union()
             .repeatForever()
                .start();
    }
}

